{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0a02c058-026b-4d9e-b9ed-c2b0588eaf80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用图书馆里系统!是否启动程序？\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入y/n:  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  1\n",
      "请输入要添加的图书名称:  james\n",
      "请输入作者姓名:  james\n",
      "请输入出版年份:  2025\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "新书添加成功!\n",
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  3\n",
      "请输入要查找的图书书名:  james\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你查找的书籍信息如下:\n",
      "书名:james,\n",
      "详细信息:{'作者姓名': 'james', '出版年份': '2025', '借阅状态': '在库'}\n",
      "是否修改图书借阅状态?\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入y/n:  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "书本借阅状态已更新!最新状态为借出\n",
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  4\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "是否查阅所有书籍详细信息?是请输入y/n\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入y/n:  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请查阅书籍清单:\n",
      "书名:james,作者姓名:james,出版年份:2025借阅状态:借出\n",
      "请问是否需要修改其中一本书籍借阅?\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入y/n:  y\n",
      "请输入要修改的图书书名:  james\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "书本借阅状态已更新!最新状态为在库\n",
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  5\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "没有已删除的图书!\n",
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  2\n",
      "请输入要删除的书名 james\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "确定要删除吗?\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入y/n:  y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  5\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "书名:james,作者姓名:james,出版年份:2025借阅状态:已删除\n",
      "\n",
      "程序功能如下,请选择:\n",
      "1.添加图书\n",
      "2.删除图书\n",
      "3.查找单个图书(可修改借阅状态)\n",
      "4.显示所有图书(可修改借阅状态)\n",
      "5.查看已删除图书\n",
      "6.退出程序\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入你想使用的功能(数字1-6):  6\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "感谢!\n"
     ]
    }
   ],
   "source": [
    "#程序项目:图书馆里系统\n",
    "books_normal={}\n",
    "books_deleted={}\n",
    "books_deleted_info={}\n",
    "\n",
    "def get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n']):#设置限制参数循环y/n，下面备用\n",
    "    while True:\n",
    "        choice=input(prompt).strip()\n",
    "        if choice in valid_choice:\n",
    "            return choice\n",
    "        else:\n",
    "            print('输入非法请重新输入!')\n",
    "\n",
    "def empty_or_not():\n",
    "    empty_or_not=len(books_normal)\n",
    "    return emprt_or_notx\n",
    "\n",
    "def exisit(name):\n",
    "    if name in books_normal:\n",
    "        return\n",
    "\n",
    "            \n",
    "print('欢迎使用图书馆里系统!是否启动程序？')\n",
    "choice=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "if choice=='n':\n",
    "    print('再见!')\n",
    "else:\n",
    "    while True:\n",
    "        print('\\n程序功能如下,请选择:')\n",
    "        print('1.添加图书')\n",
    "        print('2.删除图书')\n",
    "        print('3.查找单个图书(可修改借阅状态)')\n",
    "        print('4.显示所有图书(可修改借阅状态)')\n",
    "        print('5.查看已删除图书')\n",
    "        print('6.退出程序')\n",
    "        func_choice=input('请输入你想使用的功能(数字1-6): ').strip()\n",
    "        \n",
    "        if func_choice=='1':\n",
    "            book_id=input('请输入要添加的图书名称: ').strip()\n",
    "                \n",
    "            if book_id in books_normal:\n",
    "                print('图书已存在，请输入新书书名!')\n",
    "            elif book_id not in books_normal:\n",
    "                author=input('请输入作者姓名: ').strip()\n",
    "                yop=input('请输入出版年份: ').strip()\n",
    "                status='在库'\n",
    "\n",
    "                books_info={\n",
    "                    '作者姓名':author if author else None,\n",
    "                    '出版年份':yop if yop else None,\n",
    "                    '借阅状态':status if status else None\n",
    "                }\n",
    "\n",
    "                books_normal[book_id]=books_info\n",
    "                print('新书添加成功!')\n",
    "            else:\n",
    "                print('非法输入!请重新输入有效书名')\n",
    "                              \n",
    "        if func_choice=='2':\n",
    "            if empty_or_not==0:\n",
    "                print('没有可删除的书籍!')\n",
    "            else: \n",
    "                del_book=input('请输入要删除的书名').strip()\n",
    "                if del_book in books_normal:#这个也应该可以用while循环\n",
    "                    print('确定要删除吗?')\n",
    "                    choice2=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "                    if choice2=='y':\n",
    "                        books_deleted_info=books_normal[del_book]\n",
    "                        books_deleted[del_book]=books_deleted_info\n",
    "                        del books_normal[del_book]\n",
    "                        books_deleted_info['借阅状态']='已删除'\n",
    "\n",
    "                    else:\n",
    "                        print('再见!')\n",
    "                                \n",
    "                else:\n",
    "                    print('未查到要删除的书籍，请重新输入!')\n",
    "\n",
    "        if func_choice=='3':\n",
    "            if empty_or_not==0:\n",
    "                print('没有可查找的书籍!')\n",
    "            else:\n",
    "                search_book=input('请输入要查找的图书书名: ').strip()\n",
    "                if search_book in books_normal:\n",
    "                    print(f'你查找的书籍信息如下:\\n书名:{search_book},\\n详细信息:{books_normal[search_book]}')\n",
    "                    print('是否修改图书借阅状态?')\n",
    "                    choice3=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "                    if choice3=='y':\n",
    "                        if '在库' in books_normal[search_book].values():\n",
    "                            books_normal[search_book]['借阅状态']='借出'\n",
    "                            print(f'书本借阅状态已更新!最新状态为{books_normal[search_book]['借阅状态']}')\n",
    "                        else:\n",
    "                            books_normal[search_book]['借阅状态']='在库'\n",
    "                            print(f'书本借阅状态已更新!最新状态为{books_normal[search_book]['借阅状态']}')\n",
    "                    else:\n",
    "                        print('谢谢使用!')\n",
    "                else:\n",
    "                    print('书名不存在或输入非法!')\n",
    "                      \n",
    "        if func_choice=='4':\n",
    "            if empty_or_not==0:\n",
    "                print('没有可查阅的图书!')\n",
    "            else:\n",
    "                print('是否查阅所有书籍详细信息?是请输入y/n')\n",
    "                detail_ornot=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "                if detail_ornot=='n':\n",
    "                    for names in books_normal:\n",
    "                        print(f'请查阅书籍清单:\\nn-{names}')\n",
    "                    print('请问是否需要查阅其中一本书籍详细信息?')\n",
    "                    choice4=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "                    if choice4=='y':\n",
    "                        show_detail_id=input('请输入要查找的图书书名: ').strip()\n",
    "                        if show_detail_id in books_normal:\n",
    "                            print(f'你查阅的书籍详细信息如下:\\n书名:{search_book},\\n详细信息:{books_normal[show_detail_id]}')\n",
    "                            print('是否修改图书借阅状态?')\n",
    "                            choice5=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "                            if choice5=='y':\n",
    "                                if '在库' in books_normal[show_detail_id].values():\n",
    "                                    books_normal[show_detail_id]['借阅状态']='借出'\n",
    "                                    print(f'书本借阅状态已更新!最新状态为{books_normal[show_detail_id]['借阅状态']}')\n",
    "                                else:\n",
    "                                    books_normal[show_detail_id]['借阅状态']='在库'\n",
    "                                    print(f'书本借阅状态已更新!最新状态为{books_normal[show_detail_id]['借阅状态']}')\n",
    "                        else:\n",
    "                            print('书名不存在或输入非法!')\n",
    "\n",
    "                    else:\n",
    "                        print('谢谢使用!')\n",
    "                else:\n",
    "                    print('请查阅书籍清单:')\n",
    "                    for k,v in books_normal.items():\n",
    "                        print(f'书名:{k},作者姓名:{v['作者姓名']},出版年份:{v['出版年份']}借阅状态:{v['借阅状态']}')\n",
    "                        print('请问是否需要修改其中一本书籍借阅?')\n",
    "                        choice6=get_valid_input(prompt='请输入y/n: ',valid_choice=['y','n'])\n",
    "                        if choice6=='y':\n",
    "                            change_detail_id=input('请输入要修改的图书书名: ').strip()\n",
    "                            if change_detail_id in books_normal:\n",
    "                                if '在库' in books_normal[change_detail_id].values():\n",
    "                                    books_normal[change_detail_id]['借阅状态']='借出'\n",
    "                                    print(f'书本借阅状态已更新!最新状态为{books_normal[change_detail_id]['借阅状态']}')\n",
    "                                else:\n",
    "                                    books_normal[change_detail_id]['借阅状态']='在库'\n",
    "                                    print(f'书本借阅状态已更新!最新状态为{books_normal[change_detail_id]['借阅状态']}')\n",
    "                            else:\n",
    "                                print('书名不存在或输入非法!')\n",
    "                        else:\n",
    "                            print('谢谢使用!')\n",
    "\n",
    "        if func_choice=='5':\n",
    "            if len(books_deleted)==0:\n",
    "                print('没有已删除的图书!')\n",
    "            else:\n",
    "                for k,v in books_deleted.items():\n",
    "                    print(f'书名:{k},作者姓名:{v['作者姓名']},出版年份:{v['出版年份']}借阅状态:{v['借阅状态']}')\n",
    "\n",
    "        if func_choice=='6':\n",
    "            print('感谢!')\n",
    "            break\n",
    "\n",
    "    else:\n",
    "        print('输入非法!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea6bfafb-8323-4233-b3e3-28267427d511",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
